package org.example.hikvisiontest.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum CameraIP {
    CameraIP_10("10.255.2.10","10_afan"),
    CameraIP_7("10.255.2.7","7_zlzx"),
    CameraIP_8("10.255.2.8","8_mbdj"),
    CameraIP_5("10.255.2.5","5_zljc");
    private final String ipAddress;
    private final String name;
    public static String findEnumByIP(String ipAddress) {
        for (CameraIP item : values()) {
            if (item.getIpAddress().equals(ipAddress)) {
                //如果需要直接返回code则更改返回类型为String,return statusEnum.code;
                return item.getName();
            }
        }
        throw new IllegalArgumentException("name is invalid");
    }


    public static List<Map<String, String>> toList() {
        List<Map<String, String>> list = new ArrayList<>();
        for (CameraIP item : values()) {
            Map<String, String> map = new HashMap<>();
            map.put("name", item.getName());
            map.put("ipAddress", item.getIpAddress());
            list.add(map);
        }
        return list;
    }

    public static List<String> toIpList() {
        List<String> list = new ArrayList<>();
        for (CameraIP item : values()) {

            list.add(item.getIpAddress());
        }
        return list;
    }
}
